<template>
  <common-list>
    <common-table
      slot="content"
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
    >
      <!--<el-table-column type="selection" width="55" align="left" />-->

      <el-table-column label="策略名称" align="left">
        <template slot-scope="{ row }">{{ row.ruleName }}</template>
      </el-table-column>

      <el-table-column label="图形验证码" align="left">
        <template slot-scope="{ row }">
          {{
            row.pictureVercodeFlag == 0
              ? "启用"
              : row.pictureVercodeFlag == 1
              ? "不启用"
              : "登录失败" + row.pictureVercodeFailCount + "次后启用"
          }}
        </template>
      </el-table-column>

      <el-table-column label="账号冻结" align="left">
        <template slot-scope="{ row }">{{
          "登录失败" + row.loginFailCountFreeze + "次后冻结账号"
        }}</template>
      </el-table-column>

      <el-table-column label="操作" align="left" width="52">
        <template slot-scope="{ row }">
          <el-button
            type="text"
            @click="edit(row)"
            v-hasPermi="['system:loginrule:updateSystemLoginRule']"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </common-table>

    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList"
    />
    <!-- 列表 end -->
    <editDialog ref="editDialog" @refresh="getList" />
  </common-list>
</template>

<script>
import { loginrule_querySystemLoginRulePageList } from "@/api/management/configure/index.js";
import editDialog from "./components/loginDialog";
import BaseList from "@/mixins/BaseList";

export default {
  mixins: [BaseList],
  components: { editDialog },
  props: {},
  data() {
    return {
      total: 1, // 总条数
      loading: false, // table 加载中
      list: [], // 数据列
      selectionIds: "", // 列表选中数据id
      single: true, // 非单个禁用
      multiple: true, // 非多个禁用
      query: {
        pageNum: 1,
        pageSize: 10,
      }, // 查询条件
    };
  },
  watch: {},
  computed: {},
  methods: {
    /**
     * 选择
     */
    handleSelectionChange(selection) {
      this.selectionIds = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /**
     * 获取列表
     */
    getList() {
      this.$emit("itemclick");
      this.loading = true;
      loginrule_querySystemLoginRulePageList({ ...this.query })
        .then((res) => {
          if (res && res.code === 200) {
            this.list = res.rows;
            this.total = res.total;
          } else {
            this.list = [];
            this.total = 0;
            this.handleListTips(res);
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * 添加/编辑
     */
    edit(row) {
      this.$refs.editDialog.show(row ? { ...row } : {});
    },
  },
  created() {
    this.getList();
  },
  mounted() {},
};
</script>
<style lang="scss"></style>
